import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class BookListFragment extends Fragment {
    private RecyclerView recyclerView;
    private BookAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // 加载fragment_book_list.xml布局
        View view = inflater.inflate(R.layout.fragment_book_list, container, false);
        // 找到RecyclerView控件
        recyclerView = view.findViewById(R.id.recycler_view);
        // 设置列表为线性布局
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        // 绑定你已有的BookAdapter和图书数据
        adapter = new BookAdapter(BookStorageUtil.getBooks());
        recyclerView.setAdapter(adapter);
        return view;
    }
}
